package com.lucy.common.core;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author kindear
 * 基础实体类
 */
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "基础实体类")
public abstract class BaseEntity {
    @Id
    @GenericGenerator(name = "id",strategy = "com.lucy.common.generator.SnowIdGenerator")
    @GeneratedValue(generator = "id")
    @ApiModelProperty(value = "雪花ID",name = "id")
    private String id;

    @CreatedBy
    @ApiModelProperty(value = "记录创建者",name = "createdTime")
    @Column(name = "create_user_id")
    private Long createUserId;


    @LastModifiedBy
    @Column(name = "modify_user_id")
    @ApiModelProperty(value = "记录修改者",name = "createdTime")
    private Long modifyUserId;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;
}